#pragma once
#include <vector>
#include <SDL/SDL.h>
#include <SDL/SDL_events.h>
#include <SDL/SDL_ttf.h>

struct Padding{
    int left,top,right,bottom;
};

struct Margin{
    int left,top,right,bottom;
};

class Component{
    public:
        Component() = default;
        ~Component();
        virtual int update(float delta);
        virtual void render(SDL_Renderer* render);
        int handleEvent(SDL_Event &evt);
        void setPosition(int x, int y);
        const SDL_Rect& getRect() ;
        void setFont(TTF_Font * font);
        static void setDefaultFont(TTF_Font * font);
        const TTF_Font* getFont(); 
    protected:
        Component* parent{nullptr};
        std::vector<Component*> children;
        SDL_Rect abs_rect={0,0,200,200};
        SDL_Rect rect={0,0,200,200};
        SDL_Color bk_color = {0xff,0xff,0xff,0xff};
        SDL_Color fr_color = {0,0,0,0xff};
        SDL_Color bd_color = {0,0,0,0xff};
        bool inRect = false;
        bool focused = false;
        bool pressed = false;
        int border_tickness = 2;
        bool db_clicked = false;

        virtual void mouseHover(SDL_MouseMotionEvent &evt);
        virtual void mouseEnter(SDL_MouseMotionEvent &evt);
        virtual void mouseLeave(SDL_MouseMotionEvent &evt);
        virtual void mouseClick(SDL_MouseButtonEvent &evt);
        virtual void mousePress(SDL_MouseButtonEvent &evt);
        virtual void mouseRelease(SDL_MouseButtonEvent &evt);
        virtual void mouseDbClick(SDL_MouseButtonEvent &evt);
        static bool isInRect(SDL_Rect &rc, int x, int y);

        Padding padding = {6,6,6,6};
        Margin margin;

        TTF_Font * font=nullptr; 
        static TTF_Font * default_font;

};